package Swing;
/*
*多选框和单选框
 */
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;

public class JButton_Demo02 extends JFrame {
    public JButton_Demo02() throws IOException {
        Container contentPane = this.getContentPane();
        //将一个图片变成图标
//        URL resource =  JButton_Demo.class.getResource("jetbrains://idea/navigate/reference?project=untitled&path=1.PNG");

        ImageIcon imageIcon = new ImageIcon(ImageIO.read(new File("src/1.PNG")));
        //单选框按钮
        JRadioButton radioButto1 = new JRadioButton("radioButto1");
        JRadioButton radioButto2 = new JRadioButton("radioButto2");
        JRadioButton radioButto3 = new JRadioButton("radioButto3");
        //这几个单选框只能被选中一个，进行分组设置，一个组里面只有一个被选中
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(radioButto1);
        buttonGroup.add(radioButto2);
        buttonGroup.add(radioButto3);
        contentPane.add(radioButto1,BorderLayout.CENTER);
        contentPane.add(radioButto2,BorderLayout.SOUTH);
        contentPane.add(radioButto3,BorderLayout.NORTH);
        this.setVisible(true);
        this.setSize(500,500);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) throws IOException {
        new JButton_Demo02();
    }
}
